import request from "@/utils/request";
import {
  tokenUrl,
  url,
  selectUrl,
  changeUrl,
  checkUrl,
  clearUrl,
  pushUrl,
} from "./url";

export async function getToken(params) {
  return request({
    url: `${tokenUrl}`,
    method: "POST",
    data: params,
  });
  /*  return {
    success: true,
    message: "Token",
    code: 200,
    result: {
      token:
        "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjA5ODgwMDksInVzZXJuYW1lIjoiYWRtaW4ifQ.ymD_8u2E2zI4WoVFhdi0TyO6e359x2cspznpg-vd4HU",
    },
    timestamp: 1720685609067,
  };*/
}

export async function getSearchList(id) {
  return request({
    url: `${url}/getQueryInfoVue3/${id}`,
    method: "GET",
  });
  /*  return {
    success: true,
    message: "",
    code: 200,
    result: {
      searchFieldList: [
        "dim_lvl_code",
        "dim_lvl_comment",
        "src_table",
        "data_auth",
        "user_status",
      ],
      $schema: "http://json-schema.org/draft-07/schema#",
      joinQuery: false,
      type: null,
      title: "维度管理",
      required: null,
      properties: {
        user_status: {
          dbPointLength: 0,
          mode: "single",
          view: "radio",
          type: "string",
          title: "用户状态",
          maxLength: 32,
          order: 7,
        },
        data_auth: {
          dbPointLength: 0,
          mode: "single",
          view: "tree",
          type: "string",
          title: "数据权限",
          maxLength: 32,
          order: 7,
        },
        editor: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          type: "string",
          title: "编辑人",
          maxLength: 32,
          order: 7,
        },
        update_time: {
          dbPointLength: 0,
          mode: "single",
          view: "date",
          type: "string",
          title: "最近编辑时间",
          maxLength: 0,
          order: 8,
        },
        dim_lvl_comment: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          type: "string",
          title: "维度名称",
          maxLength: 32,
          order: 2,
        },
        value_comment: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          type: "string",
          title: "字段取值解释",
          maxLength: 64,
          order: 6,
        },
        src_field: {
          dbPointLength: 0,
          mode: "single",
          view: "textarea",
          type: "string",
          title: "来源表取值字段",
          maxLength: 192,
          order: 5,
        },
        src_table: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          type: "string",
          title: "来源表",
          maxLength: 255,
          order: 4,
        },
        dim_lvl_name: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          fieldExtendJson: "",
          type: "string",
          title: "宽表展示字段名",
          maxLength: 32,
          order: 3,
        },
        dim_lvl_code: {
          dbPointLength: 0,
          mode: "single",
          view: "text",
          ui: {
            widgetattrs: {
              disabled: true,
            },
          },
          type: "string",
          title: "维度编码",
          maxLength: 64,
          order: 1,
        },
      },
      table: "dim_dimension_level",
    },
    timestamp: 1720685609590,
  };*/
}

export async function getForm(id) {
  return request({
    url: `${url}/getFormItem/${id}`,
    method: "GET",
  });
  /* return {
    success: true,
    message: "",
    code: 0,
    result: {
      schema: {
        $schema: "http://json-schema.org/draft-07/schema#",
        describe: "维度管理",
        type: null,
        title: null,
        required: null,
        properties: {
          editor: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            type: "string",
            title: "编辑人",
            maxLength: 32,
            order: 7,
          },
          update_time: {
            dbPointLength: 0,
            mode: "single",
            view: "date",
            type: "string",
            title: "最近编辑时间",
            maxLength: 0,
            order: 8,
          },
          dim_lvl_comment: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            type: "string",
            title: "维度名称",
            maxLength: 32,
            order: 2,
          },
          value_comment: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            type: "string",
            title: "字段取值解释",
            maxLength: 64,
            order: 6,
          },
          src_field: {
            dbPointLength: 0,
            mode: "single",
            view: "textarea",
            type: "string",
            title: "来源表取值字段",
            maxLength: 192,
            order: 5,
          },
          src_table: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            type: "string",
            title: "来源表",
            maxLength: 255,
            order: 4,
          },
          dim_lvl_name: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            fieldExtendJson: "",
            type: "string",
            title: "宽表展示字段名",
            maxLength: 32,
            order: 3,
          },
          dim_lvl_code: {
            dbPointLength: 0,
            mode: "single",
            view: "text",
            ui: {
              widgetattrs: {
                disabled: true,
              },
            },
            type: "string",
            title: "维度编码",
            maxLength: 64,
            order: 1,
          },
        },
        table: "dim_dimension_level",
      },
      head: {
        id: "4028fdb79072196a0190963afe7d0004",
        tableName: "dim_dimension_level",
        tableType: 1,
        tableVersion: 21,
        tableTxt: "维度管理",
        isCheckbox: "Y",
        isDbSynch: "Y",
        isPage: "Y",
        isTree: "N",
        idSequence: null,
        idType: "NATIVE",
        queryMode: "group",
        relationType: null,
        subTableStr: null,
        tabOrderNum: null,
        treeParentIdField: null,
        treeIdField: null,
        treeFieldname: null,
        formCategory: "bdfl_include",
        formTemplate: "1",
        themeTemplate: "normal",
        formTemplateMobile: null,
        extConfigJson:
          '{"reportPrintShow":0,"reportPrintUrl":"","joinQuery":0,"modelFullscreen":0,"modalMinWidth":"","comment_status":0}',
        updateBy: "admin",
        updateTime: "2024-07-11 15:54:32",
        createBy: "admin",
        createTime: "2024-07-09 14:42:48",
        copyType: 0,
        copyVersion: null,
        physicId: null,
        hascopy: null,
        scroll: 1,
        taskId: null,
        isDesForm: "N",
        desFormCode: "",
        lowAppId: null,
        selectFieldString: null,
        selectFieldList: null,
      },
      formTemplate: "1",
    },
    timestamp: 1720685609360,
  };*/
}

export async function addData(params) {
  return request({
    url: `${changeUrl}/addForm/${params.id}`,
    method: "POST",
    data: params.formData,
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}

export async function editData(params) {
  return request({
    url: `${changeUrl}/editForm/${params.id}`,
    method: "PUT",
    data: params.formData,
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}
export async function deleteData(params) {
  return request({
    url: `${changeUrl}/deleteForm/${params.id}/${params.deleteId}`,
    method: "DELETE",
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}
export async function getTableColumns(id) {
  return request({
    url: `${url}/getColumns/${id}`,
    method: "GET",
  });
  /*  return {
    success: true,
    message: "",
    code: 0,
    result: {
      description: "维度管理",
      code: "4028fdb79072196a0190963afe7d0004",
      hasChildrenField: null,
      currentTableName: "dim_dimension_level",
      pidField: null,
      enhanceJs: null,
      desFormCode: "",
      isDesForm: "N",
      relationType: null,
      tableType: 1,
      columns: [
        {
          title: "维度编码",
          dataIndex: "dim_lvl_code",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "维度名称",
          dataIndex: "dim_lvl_comment",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "宽表展示字段名",
          dataIndex: "dim_lvl_name",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "来源表",
          dataIndex: "src_table",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "来源表取值字段",
          dataIndex: "src_field",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "字段取值解释",
          dataIndex: "value_comment",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "编辑人",
          dataIndex: "editor",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "string",
          fieldType: null,
        },
        {
          title: "最近编辑时间",
          dataIndex: "update_time",
          align: "center",
          customRender: null,
          scopedSlots: null,
          hrefSlotName: null,
          showLength: 0,
          sorter: false,
          linkField: null,
          tableName: null,
          dbType: "Datetime",
          fieldType: null,
        },
      ],
      formTemplate: "1",
      foreignKeys: [],
      fieldHrefSlots: [],
      hideColumns: [],
      dictOptions: {},
      checkboxFlag: "Y",
      cgButtonList: [],
      scrollFlag: 1,
      paginationFlag: "Y",
      textField: null,
    },
    timestamp: 1720688963425,
  };*/
}
export async function getTableBody(params) {
  console.log(params, "查询参数");
  let str = "";
  for (let key in params.searchData) {
    if (key === "superQueryParams" && params.searchData.superQueryParams) {
      str += `${key}=${JSON.stringify(params.searchData[key])}&`;
    } else {
      str += `${key}=${params.searchData[key]}&`;
    }
  }
  str = str.slice(0, str.length - 1);
  return request({
    url: `${changeUrl}/getData/${params.id}?${str}`,
    method: "GET",
  });
  /*return {
    success: true,
    message: "",
    code: 0,
    result: {
      largeValue: "S_111",
      total: 110,
      records: [
        {
          editor: "cth_test",
          update_time: "2025-02-13 09:54:32",
          jeecg_row_key: "1889855420915896322",
          kpi_name: "month_id,  USER_ID ",
          kpi_code: "S_000111",
          restrict_condition:
            "MONTH_ID between '202410' and '202412'  AND PAY_FEE_MODE<>'4' AND PAYMENT_OP='16000' group by USER_ID,month_id",
          src_table: "DWD.dwd_M_acc_cb_f_paylog",
          kpi_comment: "全渠道交费用户数_lln",
          id: "1889855420915896322",
          compute_method: "count(user_id)",
          comment_status: "-1",
          comment_text:
            '还有需要注意的是，aria-hidden的元素如果被设置为true，其子元素也会被辅助技术忽略，除非子元素显式设置了aria-hidden="false"。比如，父元素设置了aria-hidden="true"，子元素即使有内容，辅助技术也不会读取，除非子元素自己覆盖这个设置。这点需要注意，避免意外隐藏了需要被访问的内容。',
          comment_time: "2025-02-26 10:36:18",
        },
        {
          editor: "cth_test",
          update_time: "2025-02-12 18:22:42",
          jeecg_row_key: "1889621434238562305",
          kpi_name: "cn_imsi",
          kpi_code: "S_000110",
          restrict_condition: "and mcc_name = 'AUSTRALIA'",
          src_table: "o_data_model.dwd_d_gm_basic_normal",
          kpi_comment: "漫游澳大利亚用户数",
          id: "1889621434238562305",
          compute_method: "count(distinct imsi)",
          comment_status: "1",
        },
        {
          comment_status: "0",
          editor: "cth_test",
          update_time: "2025-02-07 15:35:17",
          jeecg_row_key: "1887767350653022209",
          kpi_name: "cn_user",
          kpi_code: "S_000109",
          restrict_condition:
            "AND IS_IOT = '0'       AND IS_STAT = '1'       AND SERVICE_TYPE IN ('40AAAAAA', '50AAAAAA')AND IS_THIS_DEV = '1'",
          src_table: "dwa_v_m_cus_cb_user_info",
          kpi_comment: "新发展移网用户数",
          id: "1887767350653022209",
          compute_method: "COUNT(DISTINCT T.USER_ID)",
        },
        {
          editor: "cth_test",
          update_time: "2025-02-06 14:57:03",
          jeecg_row_key: "1887395491466563586",
          kpi_name: "prov_desc,total_fee",
          kpi_code: "S_000108",
          restrict_condition: "1=1",
          src_table: "zb_serv_cth.dm_m_gongyu_kd_info_ai_sy",
          kpi_comment: "宽带出账收入",
          id: "1887395491466563586",
          compute_method: "sum(nvl(total_fee,0))",
        },
        {
          editor: "zhengyin@bonc.com.cn",
          update_time: "2025-01-23 11:36:15",
          jeecg_row_key: "1882271294913294337",
          kpi_name: "no_tax_amount",
          kpi_code: "S_000107",
          restrict_condition:
            "and catalog_code in  ('P3020203P22030100220000', 'P3020203P22030100820000', 'P4020203P22030100220000', 'P4020203P22030100820000', 'P6020203P22030100220000', 'P6020203P22030100820000', 'PA020324P22030100220000', 'PA020324P22030100820000')",
          src_table: "dwd.DWD_M_ACC_RVN_DISPENSE",
          kpi_comment: "联通云盘净额",
          id: "1882271294913294337",
          compute_method: "sum(no_tax_amount) * (-1)",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-23 11:06:22",
          jeecg_row_key: "1882263657082040322",
          kpi_name: "user_id",
          kpi_code: "S_000106",
          restrict_condition: "1=1",
          src_table: "temp_lln_guangxi_db_202409",
          kpi_comment: "广西清单用户",
          id: "1882263657082040322",
          compute_method: "user_id",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-16 11:04:20",
          jeecg_row_key: "1879726849428860930",
          kpi_name: "prov_desc,CP_TYPE",
          kpi_code: "S_000105",
          restrict_condition: "1=1",
          src_table: "zb_serv_cth.dm_m_yfsj_info_sy",
          kpi_comment: "银发数据_移网出账用户数",
          id: "1879726849428860930",
          compute_method: "count(distinct user_id)",
        },
        {
          editor: "admin",
          update_time: "2025-01-09 21:36:21",
          jeecg_row_key: "1877348693216636931",
          kpi_name: "22",
          kpi_code: "S_000104",
          restrict_condition: "12",
          src_table: "222",
          kpi_comment: "12",
          id: "1877348693216636931",
          compute_method: "33",
        },
        {
          editor: "admin",
          update_time: "2025-01-09 21:36:21",
          jeecg_row_key: "1877348693216636930",
          kpi_name: "111",
          kpi_code: "S_000103",
          restrict_condition: "1",
          src_table: "11",
          kpi_comment: "111",
          id: "1877348693216636930",
          compute_method: "1",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-09 10:11:01",
          jeecg_row_key: "1877176457495621633",
          kpi_name: "cnt",
          kpi_code: "S_000102",
          restrict_condition: "1=1",
          src_table: "dm_m_gj_srtjmx_2024",
          kpi_comment: "国际物联网Outbound业务项目个数",
          id: "1877176457495621633",
          compute_method: "count(nvl(cust_id,1))",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-09 10:01:45",
          jeecg_row_key: "1877176157284118529",
          kpi_name:
            "device_number, user_id, prov_id, month_id,area_id,service_type",
          kpi_code: "S_000101",
          restrict_condition:
            "rn = 1 and device_number in (select phone_id from dm_gz_m_gyk_cd_11 group by phone_id)",
          src_table: "DWA.DWA_V_M_CUS_CB_USER_INFO",
          kpi_comment: "轻触点用户数",
          id: "1877176157284118529",
          compute_method:
            "count(distinct nvl(b.user_id,0)), sum(nvl(TOTAL_FEE,0))",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-09 09:43:13",
          jeecg_row_key: "1877169484519747585",
          kpi_name: "cnt",
          kpi_code: "S_000100",
          restrict_condition: "1=1",
          src_table: "dm_m_ave_ls_kd_zyj_mx",
          kpi_comment: "拍照月宽带用户数",
          id: "1877169484519747585",
          compute_method: "count(distinct user_id)",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-09 09:26:10",
          jeecg_row_key: "1877165175618973698",
          kpi_name: "cn_user",
          kpi_code: "S_00099",
          restrict_condition: "1=1",
          src_table: "mid_dm_kf_jxyx_val_info_gwh",
          kpi_comment: "交叉营销新发展用户数",
          id: "1877165175618973698",
          compute_method: "count(user_id)",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-08 16:11:32",
          jeecg_row_key: "1876905194915147778",
          kpi_name: "user_id",
          kpi_code: "S_00098",
          restrict_condition:
            "MONTH_ID between '202410' and '202412'  AND PAY_FEE_MODE<>'4' AND PAYMENT_OP='16000' group by USER_ID,month_id",
          src_table: "DWD.dwd_M_acc_cb_f_paylog",
          kpi_comment: "全渠道交费用户数",
          id: "1876905194915147778",
          compute_method: "count(*)",
        },
        {
          editor: "cth_test",
          update_time: "2025-01-07 09:50:04",
          jeecg_row_key: "1876445608239738881",
          kpi_name: "total_fee",
          kpi_code: "S_00097",
          restrict_condition: "1=1",
          src_table: "zb_serv_cth.dm_m_jiangsu_xfsctz_sy",
          kpi_comment: "2024年移宽出账收入",
          id: "1876445608239738881",
          compute_method: "sum(nvl(total_fee,0)) ",
        },
      ],
    },
    timestamp: 1740540320702,
  };*/
}
export async function getSelectList(params) {
  return request({
    url: `${selectUrl}/valueCode`,
    method: "GET",
    params: params,
  });

  /*  return {
    success: true,
    message: "",
    code: 200,
    result: ["W_00002", "tes"],
    timestamp: 1720690258437,
  };*/
}
export async function checkCode(params) {
  return request({
    url: `${checkUrl}`,
    method: "GET",
    params: params,
    mark: true,
  });

  /*  return {
    success: false,
    message: "该值不可用，系统中已存在！",
    code: 500,
    result: null,
    timestamp: 1721698656796,
  };*/
}
export async function clearCache(params) {
  console.log(params, "缓存参数");
  return request({
    url: `${clearUrl}?dim=${params.dim}`,
    method: "POST",
    // params: params,
  });

  /*  return {
    success: false,
    message: "该值不可用，系统中已存在！",
    code: 500,
    result: null,
    timestamp: 1721698656796,
  };*/
}
export async function templateDownload(params) {
  return request({
    url: `${selectUrl}/exportXlsDimLevelValue`,
    method: "GET",
    params: params,
    responseType: "blob",
  });

  /*  return {
    success: false,
    message: "该值不可用，系统中已存在！",
    code: 500,
    result: null,
    timestamp: 1721698656796,
  };*/
}

export async function fileUpload(params) {
  return request({
    url: `${selectUrl}/importExcelDimLevelValue`,
    method: "POST",
    data: params,
  });

  /*  return {
    success: false,
    message: "该值不可用，系统中已存在！",
    code: 500,
    result: null,
    timestamp: 1721698656796,
  };*/
}
export async function importKnowled(params) {
  console.log(params, "查询参数");
  return request({
    url: `${pushUrl}`,
    method: "POST",
    data: params,
  });
  /*  return {
    success: true,
    message: "",
    code: 200,
    result: "success",
  };*/
}
